﻿
#include "BoundaryInfo.h"

BoundaryInfo::BoundaryInfo() {}

BoundaryInfo::~BoundaryInfo() {}

std::string& BoundaryInfo::SideSetName(BoundaryId id)
{
  try
  {
    return _ss_id_to_name[id];
  }
  catch (const std::exception& e)
  {
    console::Error(e.what());
  }
}

void BoundaryInfo::AddSide(ElemId e_id, SideId s_id, BoundaryId b_id)
{
  auto range = _boundary_side_id.equal_range(e_id);

  for (const auto& pr : SimpleRange{ range.first, range.second }) // 不重复插入
    if (pr.second.first == s_id && pr.second.second == b_id)
      return;


  _boundary_side_id.emplace(e_id, std::make_pair(s_id, b_id));
  _side_boundary_ids.insert(b_id);
  _boundary_ids.insert(b_id);
}

BoundaryId BoundaryInfo::GetIdByName(const std::string& name) const
{
  for (auto& val : _ss_id_to_name)
  {
    if (val.second == name)
      return val.first;
  }
  return INVALID;
}

const std::map<BoundaryId, std::string>& BoundaryInfo::GetIdToName() const
{
  return _ss_id_to_name;
}

const std::multimap<ElemId, std::pair<SideId, BoundaryId>>& BoundaryInfo::GetSideSet() const
{
  return _boundary_side_id;
}
